/*
package com.lysj.bhp.wallet.job;


import com.lysj.bhp.wallet.base.CoinContent;
import com.lysj.bhp.wallet.domain.BitCoinWallet;
import com.lysj.bhp.wallet.util.BlockChainUtil;
import com.lysj.bhp.recharge.domain.RechargeRecord;
import com.lysj.bhp.user.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class BitcoinJob extends CoinContent {

    private static Logger logger = LoggerFactory.getLogger(BitcoinJob.class);

    */
/*第一次10秒后执行，当执行完后0.2秒再执行，保证一秒并发不超过5个*//*

    @Scheduled(initialDelay = 10000, fixedDelay = 100)
    public void queryBitcoinWallet() {
        logger.info("BitcoinJob is Starting ...");
        BitCoinWallet bitCoinWallet = bitcoinWalletRepository.findFirstByOrderByLastQueryTimeAsc();
        if (bitCoinWallet == null) {
            return;
        }
        long result = BlockChainUtil.getBitCoinBalance(bitCoinWallet.getGuid(), bitCoinWallet.getPassword());
        if (result < 0) { // !!!即使发生错误,也应该继续执行下一次的查询!!!
            logger.error("Blockchain return -1,bitcoinWalletId is " + bitCoinWallet.getBitcoinWalletId());
            bitCoinWallet.setLastQueryTime(System.currentTimeMillis());
            bitcoinWalletRepository.save(bitCoinWallet);
            return;
        }
        double realBalance = result * 1.0 / 100000000;

        if (realBalance <= bitCoinWallet.getBalance()) { //查询到的余额小于钱包得真实余额，则更新
            bitCoinWallet.setBalance(realBalance);
        } else {
            logger.info("BitcoinWallet Balance Increment,Start Record!" + bitCoinWallet.getBitcoinWalletId());
            double increase = realBalance - bitCoinWallet.getBalance(); // 增加的余额
            User user = userRepository.findOne(bitCoinWallet.getUserId());
            user.setBitcoinBalance(user.getBitcoinBalance() + increase);
            bitCoinWallet.setBalance(realBalance);
            // 创建充值记录
            RechargeRecord rechargeRecord = new RechargeRecord();
            rechargeRecord.setCoinType(1);
            rechargeRecord.setPayAmount(increase);
            rechargeRecord.setUserId(bitCoinWallet.getUserId());
            rechargeRecord.setCreateTime(new Date());
            rechargeRecordRepository.save(rechargeRecord);
            userRepository.save(user);
        }
        bitCoinWallet.setLastQueryTime(System.currentTimeMillis()); // 将最近的查询时间设置为现在
        bitcoinWalletRepository.save(bitCoinWallet);
    }


}
*/
